home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / nbapi.zip / NBTEST.C < prev   
C/C++ Source or Header  |  1991-06-21  |  5KB  |  198 lines

  1. /********************************************/
  2. /*                                          */
  3. /*    Name:NBTEST.C                         */
  4. /*                                          */
  5. /*    Purpose: TX and RX a buffer to or     */
  6. /*               from a Netbios Partner        */
  7. /*                                          */
  8. /*    Revision: 01.00.00                    */
  9. /*        Date: 06/20/91                    */
  10. /*                                          */
  11. /********************************************/
  12.  
  13. /* Include Statements */
  14. #include <stdio.h>
  15. #include <conio.h>
  16. #include <alloc.h>
  17. #include <dos.h>
  18. #include <dir.h>
  19. #include <string.h>
  20. #include "nb_api.c"
  21.  
  22. /* Global Variables */
  23. FILE *err;
  24. unsigned int length;
  25. int ret,mode;
  26. unsigned errors,bytes,ok;
  27. unsigned char loc_name_num,session_lsn;
  28. char *buffer1,*buffer2,loc_name[16],rem_name[16];
  29.  
  30. /* Global Structures */
  31. #define CLIENT        0
  32. #define HOST        1
  33. #define MAX_BUFF    63000
  34. struct NCB ncb;
  35.  
  36. /* Function Definitions */
  37. void start_session(void);
  38. void test(void);
  39. void clean_up(void);
  40.  
  41. void main(int argc, char *argv[])
  42. {
  43.  
  44.     /******* Allocate Memory for two test Buffers ******/
  45.     buffer1=(char *)farcalloc(MAX_BUFF+10,sizeof(char));
  46.     if(buffer1==NULL){
  47.         printf("ERROR: Unable to allocate first buffer!\r\n");
  48.         exit(-1);
  49.         };
  50.     buffer2=(char *)farcalloc(MAX_BUFF+10,sizeof(char));
  51.     if(buffer2==NULL){
  52.         printf("ERROR: Unable to allocate second buffer!\r\n");
  53.         exit(-1);
  54.         };
  55.  
  56.     /*** Open Error Log *****/
  57.     err=fopen("NB_ERROR.LOG","a+b");
  58.     if(err==NULL){
  59.         cprintf("ERROR: Unable to open Error Log\r\n");
  60.         farfree(buffer1);
  61.         farfree(buffer2);
  62.         };
  63.  
  64.     /*** Display Logo ****/
  65.     textcolor(WHITE);
  66.     cprintf("\r\n\r\n         Netbios Test Utility\r\n");
  67.     cprintf("     Dawn Development Corp.   1991\r\n");
  68.     if(argc<2){
  69.         cprintf("sytax: nbtest <[H]ost/[C]lient>\r\n");
  70.         farfree(buffer1);
  71.         farfree(buffer2);
  72.         exit(0);
  73.         };
  74.     if(!check_nb_install()){
  75.         cprintf("\r\nERROR: Netbios NOT Installed..\r\n");
  76.         exit(-2);
  77.         };
  78.  
  79.     /*** Check Command Line ***/
  80.     argv[1][0]=toupper(argv[1][0]);
  81.     if(argv[1][0]=='H'){
  82.         mode=HOST;
  83.         }
  84.     else{
  85.         mode=CLIENT;
  86.         };
  87.  
  88.     test();
  89.  
  90.     /******** Clean Up ***********/
  91.     farfree(buffer1);
  92.     farfree(buffer2);
  93.     fcloseall();
  94.     clean_up();
  95.  
  96. }
  97.  
  98. void start_session(void)
  99. {
  100.     /***************** START SESSION ************************/
  101.     if(mode==HOST){
  102.         strcpy(loc_name,"HOST");
  103.         strcpy(rem_name,"CLIENT");
  104.         }
  105.     else{
  106.         strcpy(loc_name,"CLIENT");
  107.         strcpy(rem_name,"HOST");
  108.         };
  109.     cprintf("\r\nAdding LOCAL Name to Table\r\n");
  110.  
  111.     /*********** Add Local Name and Call or Listen for Remote *********/
  112.     ncb=add_name(loc_name);
  113.     if(ncb.NCB_RETCODE!=0){
  114.         cprintf("ERROR: Unable to ADD Local Name!\r\n");
  115.         cprintf("ERROR: %Xh\r\n",ncb.NCB_RETCODE);
  116.         exit(-1);
  117.         };
  118.     loc_name_num=ncb.NCB_NUM;
  119.  
  120.     if(mode==HOST){
  121.         ncb=listen(rem_name,loc_name,1250);
  122.         if(ncb.NCB_RETCODE!=0){
  123.             cprintf("ERROR: Unable to Listen for Remote!\r\n");
  124.             cprintf("ERROR: %Xh\r\n",ncb.NCB_RETCODE);
  125.             clean_up();
  126.             };
  127.         session_lsn=ncb.NCB_LSN;
  128.         }
  129.     else{
  130.         ncb=call(rem_name,loc_name,60);
  131.         if(ncb.NCB_RETCODE!=0){
  132.             cprintf("ERROR: Unable to Call Host!\r\n");
  133.             cprintf("ERROR: %Xh\r\n",ncb.NCB_RETCODE);
  134.             clean_up();
  135.             };
  136.         session_lsn=ncb.NCB_LSN;
  137.         };
  138.  
  139. }
  140.  
  141. void test(void)
  142. {
  143.     start_session();
  144.     if(mode==CLIENT){
  145.         memset(&buffer1,'C',MAX_BUFF);
  146.         ncb=send((char *)&buffer1,MAX_BUFF,session_lsn);
  147.         if(ncb.NCB_RETCODE!=0){
  148.             cprintf("ERROR: Send Failed!\r\n");
  149.             cprintf("ERROR: %02Xh\r\n",ncb.NCB_RETCODE);
  150.             clean_up();
  151.             };
  152.         ncb=receive((char *)&buffer2,MAX_BUFF,session_lsn);
  153.         if(ncb.NCB_RETCODE!=0){
  154.             cprintf("ERROR: Receive Failed!\r\n");
  155.             cprintf("ERROR: %02Xh\r\n",ncb.NCB_RETCODE);
  156.             clean_up();
  157.             };
  158.         ret=memcmp(buffer1,buffer2,MAX_BUFF);
  159.         if(ret!=0){
  160.             error++;
  161.             }
  162.         else{
  163.             ok++;
  164.             bytes+=MAX_BUFF;
  165.             };
  166.         }
  167.     /*** Do Host Mode Stuff ****/
  168.     else{
  169.  
  170.         };
  171.  
  172. }
  173.  
  174. void clean_up(void)
  175. {
  176.     if(mode==CLIENT){
  177.         printf("\r\nTerminating Session\r\n");
  178.         ncb=hang_up(session_lsn);
  179.         if(ncb.NCB_RETCODE!=0){
  180.             cprintf("\r\nERROR: Unable to Hang Up!\r\n");
  181.             cprintf("ERROR: %Xh\r\n",ncb.NCB_RETCODE);
  182.             clean_up();
  183.             };
  184.         };
  185.  
  186.     printf("\r\nRemoving Local Name from Table...\r\n");
  187.     ncb=del_name(loc_name);
  188.     if(ncb.NCB_RETCODE!=0){
  189.         cprintf("\r\nERROR: Unable to Remove Name!\r\n");
  190.         cprintf("ERROR: %Xh\r\n",ncb.NCB_RETCODE);
  191.         clean_up();
  192.         };
  193.  
  194.     exit(0);
  195.  
  196. }
  197.  
  198.